/**
 * 
 */
package idv.takeshi.software.productline.bookstore.presentation.dto;

import javax.validation.constraints.Pattern;

import org.apache.commons.lang.Validate;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

import idv.takeshi.software.productline.bookstore.domain.model.useraccount.OrganizationAccount;
import idv.takeshi.software.productline.bookstore.domain.model.useraccount.Sex;
import idv.takeshi.software.productline.bookstore.domain.model.useraccount.UserAccountFactory;

/**
 * A data-transfer object for Organization account model.
 * @author takeshi
 *
 */
public class OrganizationAccountDto extends UserAccountDto<OrganizationAccount> {
	
	@Pattern(regexp = ".+")
	private String name;

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}


	/* (non-Javadoc)
	 * @see idv.takeshi.software.productline.bookstore.presentation.dto.UserAccountDto#createModel(idv.takeshi.software.productline.bookstore.domain.model.useraccount.UserAccountFactory)
	 */
	@Override
	public OrganizationAccount createModel(UserAccountFactory userAccountFactory) {
		Validate.notNull(userAccountFactory, "userAccountFactory shall always not be null");
		
		OrganizationAccount account = userAccountFactory.newInstance(OrganizationAccount.class, this.getAccountName());
		
		account.setOriginalPassword(this.getPassword());
		account.setZipCode(this.getZipCode());
		account.setContactAddress(this.getContactAddress());
		account.setContactPhoneNumber(this.getContactPhoneNumber());
		account.setCellPhoneNumber(this.getCellPhoneNumber());
		account.setEmailAddress(this.getEmailAddress());
		account.setName(this.getName());

		return account;
	}

	/* (non-Javadoc)
	 * @see idv.takeshi.software.productline.bookstore.presentation.dto.UserAccountDto#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj == null) { return false; }
		   if (obj == this) { return true; }
		   if (obj.getClass() != getClass()) {
		     return false;
		   }
		   OrganizationAccountDto rhs = (OrganizationAccountDto) obj;
		   return new EqualsBuilder()
		   	   .appendSuper(super.equals(rhs))
			   .append(this.name, rhs.name)
		       .isEquals();
	}

	/* (non-Javadoc)
	 * @see idv.takeshi.software.productline.bookstore.presentation.dto.UserAccountDto#hashCode()
	 */
	@Override
	public int hashCode() {
		return new HashCodeBuilder(11, 13).
		   appendSuper(super.hashCode()).
	       append(this.name).
	       toHashCode();
	}

}
